﻿package main 
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author ...
	 */
	public class SeaFieldCircle extends SeaField {
		public function SeaFieldCircle(radius:int) {
			super();
			
			// すき間が見えてしまうのでちょっと重ねる
			bmp1 = newImage(radius, 0);
			bmp2 = newImage(radius, -bmp1.height + 1);
			getSprite().addChild(bmp1);
			getSprite().addChild(bmp2);
		}
		
		public function advance(length:Number):void {
			bmp1.y += length;
			bmp2.y += length;
			if (bmp1.y >= bmp1.height / 2) {
				bmp1.y -= 2 * bmp1.height - 2;
			}
			if (bmp2.y >= bmp2.height / 2) {
				bmp2.y -= 2 * bmp2.height - 2;
			}
		}
		
		private function newMask():Sprite {
			var mask:Sprite = new Sprite();
			mask.graphics.beginFill(0xFFFFFF);
			mask.graphics.drawCircle(0, 0, radius);
			mask.graphics.endFill();
			getSprite().addChild(mask);
			return mask;
		}
		private function newImage(radius:Number, offsetY:Number):Bitmap {
			var bmp:Bitmap = new MapImage();
			bmp.x = -bmp.width / 2;
			bmp.y = offsetY;
			bmp.mask = newMask();
			return bmp;
		}
		
		private var bmp1:Bitmap;
		private var bmp2:Bitmap;
	}
	
}